package com.qianbei.common.net.view;

import com.qianbei.common.net.control.ServerControl;
import com.qianbei.common.net.control.ServerResult;
import com.qianbei.common.net.control.ServerControl.ProgressListener;
import com.qianbei.common.net.control.ServerControl.ServerListener;

public abstract class BaseProgressDialog implements ServerListener,
		ProgressListener {

	private ServerControl sc;
	private ServerListener serverListener;
	private boolean isUserBreak;

//	public void startControl(ServerControl sc, String describe) {
//		this.sc = sc;
//		serverListener = sc.serverListener;
//		sc.serverListener = this;
//		sc.progressListener = this;
//		showProgress(describe);
//		sc.startVolley();
//	}

	public void startControl(ServerControl sc) {
		this.startControl(sc, "正在加载");
	}

	public void OKpost(ServerControl sc) {
		this.OKpost(sc, "正在加载");
	}
	public void startControl(ServerControl sc, String describe) {
		this.sc = sc;
		serverListener = sc.serverListener;
		sc.serverListener = this;
		sc.progressListener = this;
		showProgress(describe);
		sc.startVolley();
	}
	public void OKpost(ServerControl sc, String describe) {
		this.sc = sc;
		serverListener = sc.serverListener;
		sc.serverListener = this;
		sc.progressListener = this;
		showProgress(describe);
		sc.OKpost();
	}
	public void OKpost1(ServerControl sc, String describe) {
		this.sc = sc;
		serverListener = sc.serverListener;
		sc.serverListener = this;
		sc.progressListener = this;
		showProgress(describe);
		sc.OKpost1();
	}
	public void OKpost1_url(ServerControl sc, String describe) {
		this.sc = sc;
		serverListener = sc.serverListener;
		sc.serverListener = this;
		sc.progressListener = this;
		showProgress(describe);
		sc.OKpost1_url();
	}

	public void startControlUPpic(ServerControl sc) {
		this.sc = sc;
		serverListener = sc.serverListener;
		sc.serverListener = this;
		sc.progressListener = this;
		showProgress("正在上传");
		sc.OkhttpUpLoadImage();
	}

//	public void startControlget(ServerControl sc, String describe) {
//		this.sc = sc;
//		serverListener = sc.serverListener;
//		sc.serverListener = this;
//		sc.progressListener = this;
//		showProgress(describe);
//		sc.startVolleyGet();
//	}

	public void userBreak() {
		isUserBreak = true;
	}

	@Override
	public void serverFinish(ServerResult sr) {
		if (!isUserBreak) {
			progressFinish();
			if (serverListener != null) {
				serverListener.serverFinish(sr);
			}
		}
		isUserBreak = false;
	}

	@Override
	public abstract void progressRate(int value);

	public abstract void showProgress(String describe);

	public abstract void progressFinish();
}
